package huawei.nk;

import java.util.Scanner;

public class HJ65 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String a= sc.nextLine();
        String b= sc.nextLine();
        int[][] dp =new int[a.length()+1][b.length()+1];
        int max=0;
        int maxIndex=0;
        for (int i = 1; i < dp.length; i++) {
            for (int j = 1; j < dp[i].length; j++) {
                if(a.charAt(i-1)==b.charAt(j-1)){
                    dp[i][j]=dp[i-1][j-1]+1;
                    if(dp[i][j]>max){
                        max=dp[i][j];
                        maxIndex=i;
                    }
                }
            }
        }
        System.out.println(a.substring(maxIndex-max,maxIndex));
        sc.close();
    }
}
